<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org/">
<head>
    <title>Title</title>
    <link rel="stylesheet"  th:href="@{/static/layui/css/layui.css}">
</head>
<body>
<form class="layui-form" action="" lay-filter="Filter">
    <input type="hidden" name="id">
    <div class="layui-form-item">
        <div class="layui-input-block">
            <textarea id="contentId" name="commit" placeholder="请输入内容" class="layui-textarea"></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block"> <button type="submit" class="layui-btn" lay-submit="" lay-filter="formFilter">立即提交</button> <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script th:src="@{/static/js/jquery-2.1.4.js}" type="text/javascript" charset="utf-8"></script>
<script th:src="@{/static/layui/layui.js}" type="text/javascript" charset="utf-8"></script>
<script th:src="@{/static/js/mylayer.js}" type="text/javascript" charset="utf-8"></script>
<script th:src="@{/static/kindeditor/kindeditor/kindeditor.js}" type="text/javascript" charset="utf-8"></script>
<script>
    //富文本编辑器
    var kindEditorParams = {
        afterBlur: function() {
            this.sync();
        }
    };
    //关联一下
    var contentId = KindEditor.create('#contentId',kindEditorParams);


    layui.use(['form'], function() {
        var form = layui.form;
        var upload = layui.upload;
        var layer = layui.layer;
        var element = layui.element;
        var $ = layui.$;
        form.render();
        //获取id值
        var queryString = window.location.search;
        var urlParams = new URLSearchParams(queryString);
        var id = urlParams.get("id");
        //先查找，再添加
        //写一个Ajax请求，获取当前id下的所有blog值
        $.post(
            //虽然是在blog里调用的是selectById方法，但是要把type的selectAll一起打包发回来
            '/project/selectById',
            //把id传过去
            {"id":id},//应该只用传id吗
            function (result) {
                console.log('result:')
                console.log(result);
                form.val('Filter',result.data);
                contentId.html(result.data.commit);//contentId是kindEditor的名字
            },
            'json'
        )
        //监听提交
        form.on('submit(formFilter)', function (data) {

            console.log(data.field);
            $.post(
                '/project/update',
                data.field,
                function (result) {
                    console.log(result)
                    if (result.code == 0){
                        mylayer.okMsg(result.msg);
                        //关闭弹窗
                        setInterval(function () {
                            //关闭弹出层
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                            //刷新父页面
                            window.parent.location.reload();
                        }, 2000);
                    }
                },
                'json'
            )
            return false;
        });
    })
</script>
</body>
</html>
